package com.asdan.seededu.front.service.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.asdan.seededu.front.service.ProjectService;
import com.asdan.seededu.util.DatabaseAccess;


public class ProjectServiceImpl implements ProjectService {

	@Override
	public boolean toNextStep(int stepid ,int uid){
		boolean temp = true ;
		DatabaseAccess databaseAccess = new DatabaseAccess(false);
		Connection cn = null;
		PreparedStatement pstmt=null;
		String sql = "update  userdata  set  stepid =? , stepstatus =?  where uid= ? AND stepid =? " ;
		try {
			cn = databaseAccess.getConn() ;
			pstmt = cn.prepareStatement(sql) ;
			pstmt.setInt(1,stepid+1) ;
			pstmt.setInt( 2, 0) ;
			pstmt.setInt(3, uid) ;
			pstmt.setInt(4, stepid) ;
			pstmt.executeUpdate() ;
		} catch (SQLException e) {
			temp = false ;
			e.printStackTrace();
		}finally{
			try {
				pstmt.close() ;
				cn.close() ;
				databaseAccess.close() ;
			} catch (SQLException e) {
				e.printStackTrace();
			}
	}
		return temp;
	}
}
